package com.megvii.koala.tv.data;

import android.content.Context;

import com.megvii.corelib.net.MegviiHttpManager;

/**
 * Created by linyue on 16/1/24.
 */
public class TVGlobalData
{
    private static TVGlobalData instance;

    public MegviiHttpManager httpManager;

    public ServerManager serverManager;

    public TVBoxManager boxManager;

    public ThemeManager themeManager;

    public SurveillanceCameraManager cameraManager;

    public TVFileManager fileManager;

    private TVGlobalData()
    {
        super();
    }

    public static TVGlobalData instance()
    {
        if (instance == null)
        {
            instance = new TVGlobalData();
        }
        return instance;
    }

    public void init(Context context)
    {
        httpManager = new MegviiHttpManager(context);
        serverManager = new ServerManager();
        serverManager.init(context);
        boxManager = new TVBoxManager();
        boxManager.init(context);
        fileManager = new TVFileManager();
        fileManager.init(context);
        themeManager = new ThemeManager(serverManager);
        cameraManager = new SurveillanceCameraManager(context);
    }

    public void release()
    {
        httpManager = null;
        if (serverManager != null)
        {
            serverManager.release();
            serverManager = null;
        }
        if (boxManager != null)
        {
            boxManager.release();
            boxManager = null;
        }
        if (themeManager != null)
        {
            themeManager.clear();
            themeManager = null;
        }
        if (cameraManager != null)
        {
            cameraManager.clear();
            cameraManager = null;
        }
    }
}
